﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using YAPL.Language.Ast;
using YAPL.Util;

namespace YAPL.Language.SourceParser.XML.NodeParsers {
	public class XmlWhileParser : XmlExpressionParser {
		public XmlWhileParser(XmlInputParser parser) : base(parser) {}
		public override Expression ParseNode(XElement node) {
			var conditionNode = node.Element(XmlNames.WhileConditionExpression);
			Require.NotNull(conditionNode);
			var conditionExpr = Parser.ParseNode(conditionNode.Elements().First());

			var bodyNode = node.Element(XmlNames.WhileBodyExpression);
			Require.NotNull(bodyNode);
			var bodyExpr = (CodeBlockExpression)Parser.ParseNode(bodyNode);

			return Expressions.While(conditionExpr, bodyExpr);
		}
	}
}
